package cn.haocxy.jfm.gui;

import javafx.scene.Node;
import javafx.scene.layout.VBox;
import cn.haocxy.jfm.filelist.FileItem;



public final class FileItemGUI {

	private final FileListPane fileListPane;
	
	private final FileItem model;

	private final VBox root = new VBox();
	
	private final IconArea iconArea;
	
	private final NameArea nameArea;
	
	public FileItemGUI(FileListPane fileListPane, FileItem model) {
		
		this.fileListPane = fileListPane;
		this.model = model;
		
		iconArea = new IconArea(this);
		nameArea = new NameArea(this);
		root.getChildren().add(iconArea.toNode());
		root.getChildren().add(nameArea.toNode());
		root.setUserData(this);
		
		initHandlerForModel();
	}

	public FileListPane getFileListPane() {
		return fileListPane;
	}
	
	public IconArea getIconArea() {
		return iconArea;
	}
	
	public NameArea getNameArea() {
		return nameArea;
	}
	
	private void initHandlerForModel() {
		
		model.getSelectEventHandlers().addHandler(e -> iconArea.update(true));

		model.getUnselectEventHandlers().addHandler(e -> iconArea.update(false));
		
	}

	public FileItem getModel() {
		return model;
	}
	
	public Node toNode() {
		return root;
	}
}
